<?php

class estate extends entity
{
    public $structs = [
        'name' => '',
        'is_auto_manage_value' => '',
        'output_address_slot_id' => '',
    ];

    public static $entity_display_name = '小区';
    public static $entity_description = '小区';

    const IS_AUTO_MANAGE_VALUE_YES = 1;
    const IS_AUTO_MANAGE_VALUE_NO = 0;

    const IS_AUTO_MANAGE_VALUE_MAPS = [
        self::IS_AUTO_MANAGE_VALUE_YES => '是',
        self::IS_AUTO_MANAGE_VALUE_NO => '否',
    ];

    public function __construct()
    {/*{{{*/
        $this->belongs_to('output_address_slot', 'address_slot', 'output_address_slot_id');
        $this->has_many('address_slots', 'address_slot');
    }/*}}}*/

    public static function create()
    {/*{{{*/
        return parent::init();
    }/*}}}*/

    public function delete_relation_entities()
    {/*{{{*/
        relationship_batch_load($this->address_slots, 'address_unit_turns');

        foreach ($this->address_slots as $address_slot) {

            $address_slot->delete_relation_entities();
            $address_slot->delete();
        }
    }/*}}}*/

    public function get_is_auto_manage_value_description()
    {/*{{{*/
        return self::IS_AUTO_MANAGE_VALUE_MAPS[$this->is_auto_manage_value];
    }/*}}}*/

    public function is_auto_manage_value_yes()
    {/*{{{*/
        return $this->is_auto_manage_value == self::IS_AUTO_MANAGE_VALUE_YES;
    }/*}}}*/

    public function is_auto_manage_value_no()
    {/*{{{*/
        return $this->is_auto_manage_value == self::IS_AUTO_MANAGE_VALUE_NO;
    }/*}}}*/

    public function is_output_address_slot(address_slot $address_slot)
    {/*{{{*/
        return $this->output_address_slot_id == $address_slot->id;
    }/*}}}*/
}
